//
//  YZNetworkManager+BankCard.m
//  YZMicroStock
//
//  Created by wangminhong on 16/4/18.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZClient+BankCard.h"

@implementation YZNetworkManager (BankCard)

- (void)bc_fetchBankListWithSuccess:(void (^)(NSURLResponse *, id))success failure:(void (^)(NSError *))failure{
    
    [self.mainNetwork cq_noCacheGET: URL_FOR_FETCH_BANK_LIST parameters: @{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE}
                            success:^(NSURLSessionDataTask *task, id resObj) {
                                if (success) {
                                    
                                    success(task.response, resObj);
                                }
                            } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
                                if (failure) {
                                    failure(error);
                                }
                            }];
}


- (void)bc_fetchCardListWithSuccess:(void (^)(NSURLResponse *, id))success failure:(void (^)(NSError *))failure{
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_FETCH_CARD_LIST parameters: @{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE}
                            success:^(NSURLSessionDataTask *task, id resObj) {
                                if (success) {
                                    
                                    success(task.response, resObj);
                                }
                            } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
                                if (failure) {
                                    failure(error);
                                }
                            }];
}

- (void)bc_fetchBranchListWithBankName:(NSString *)bankName andProvince:(NSString *)province andCity:(NSString *)city success:(void (^)(NSURLResponse *, id))success failure:(void (^)(NSError *))failure{
    
    NSDictionary *params = @{@"bankName":bankName, @"province":province, @"city":city,COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_FETCH_BRANCH_LIST parameters: params
                             success:^(NSURLSessionDataTask *task, id resObj) {
                                 if (success) {
                                     
                                     success(task.response, resObj);
                                 }
                             } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)bc_modifyBankCardWithCardID:(long long)cardID andBankName:(NSString *)bankName andProvince:(NSString *)province andCity:(NSString *)city andBranch:(NSString *)branch success:(void (^)(NSURLResponse *, id))success failure:(void (^)(NSError *))failure{
    
    NSDictionary *params = @{@"id":@(cardID), @"bank":bankName, @"province":province, @"city":city, @"branch":branch,COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_MODIFY_BANK_CARD parameters: params
                             success:^(NSURLSessionDataTask *task, id resObj) {
                                 if (success) {
                                     
                                     success(task.response, resObj);
                                 }
                             } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)bc_addBankCardWithBankName:(NSString *)bankName andProvince:(NSString *)province andCity:(NSString *)city andBranch:(NSString *)branch andCardNumber:(NSString *)cardNumber success:(void (^)(NSURLResponse *response, id responseObject))success failure:(void (^)(NSError *))failure{
    
    NSDictionary *params = @{@"bank":bankName, @"province":province, @"city":city, @"branch":branch,@"bankCard":cardNumber,COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_ADD_BANK_CARD parameters: params
                             success:^(NSURLSessionDataTask *task, id resObj) {
                                 if (success) {
                                     
                                     success(task.response, resObj);
                                 }
                             } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)bc_deleteBankCardWithCardID:(long long)cardID success:(void (^)(NSURLResponse *response, id responseObject))success failure:(void (^)(NSError *))failure{
    
    NSDictionary *params = @{@"cardId":@(cardID), COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_DELETE_BANK_CARD parameters: params
                             success:^(NSURLSessionDataTask *task, id resObj) {
                                 if (success) {
                                     
                                     success(task.response, resObj);
                                 }
                             } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}


- (void)bc_setDefaultBankCardWithCardID:(long long)cardID success:(void (^)(NSURLResponse *response, id responseObject))success failure:(void (^)(NSError *))failure{
    
    
     NSDictionary *params = @{@"cardId":@(cardID), COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    
    [self.mainNetwork cq_noCachePOST: URL_FOR_SET_DEFAULT_BANK_CARD parameters: params
                             success:^(NSURLSessionDataTask *task, id resObj) {
                                 if (success) {
                                     
                                     success(task.response, resObj);
                                 }
                             } failure: ^(NSURLSessionDataTask *operation, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}


@end
